package com.yssoft.controller.app.inventory;

import com.yssoft.service.inventory.NonConformityStockService;
import com.yssoft.utils.AppUtil;

import org.apache.commons.codec.DecoderException;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @类名称: NonConformityStockController
 * @类描述: 不合格品库存控制器
 * @作者: 于兴达
 * @创建时间:2018年9月12日09:19:33
 */
@CrossOrigin//解决跨域session问题
@RestController
@RequestMapping("/app/nonConformityStock")
public class NonConformityStockController {
    
    @Resource
    private NonConformityStockService nonConformityStockService;
    
    /**
     * @方法名称: getNonConformityList
     * @功能描述: 获取不合格品商品库存列表
     * @作者: 于兴达
     * @创建时间:2018年9月12日09:14:06
     * @param page 当前页数
     * @param limit 每页条数
     * @param companyId 企业id
     * @param tMid 商品id
     * @param type 商品类型
     * @return Object
     */
    @RequestMapping(value = "getNonConformityStockList",method = RequestMethod.GET)
    @ResponseBody
    public Object getNonConformityStockList(int page, int limit, Integer companyId,Integer tMid,String type) {
    	 if (null == companyId) {
             return AppUtil.returnMapJson("0", "查询失败，请传递企业id", null);
    	 }
         try {
             List<Map<String, Object>> nonConformityStockList = nonConformityStockService.getNonConformityStockList(page, limit, companyId,tMid,type);
             return AppUtil.returnListJson("1", "查询成功!", nonConformityStockList);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "查询失败!"+e.getMessage(), null);
         }
    }
    /**
     * @方法名称: getNonConformityList
     * @功能描述: 获取不合格品各个批次的库存列表
     * @作者: 于兴达
     * @创建时间:2018年9月12日09:14:06
     * @param page 当前页数
     * @param limit 每页条数
     * @param tnonId 不合格记录id
     * @return Object
     */
    @RequestMapping(value = "getNonConformityStockListyBatch",method = RequestMethod.GET)
    @ResponseBody
    public Object getNonConformityStockListyBatch(int page, int limit,Integer tnonId) {
    	 if (null == tnonId) {
             return AppUtil.returnMapJson("0", "查询失败，请传递不合格记录id", null);
         } 
         try {
             List<Map<String, Object>> nonConformityStockList = nonConformityStockService.getNonConformityStockListyBatch(page, limit, tnonId);
             return AppUtil.returnListJson("1", "查询成功!", nonConformityStockList);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "查询失败!"+e.getMessage(), null);
         }
    }
    /**
     * @方法名称: getGoodsList
     * @功能描述: 获取本企业成品和半成品
     * @作者: 于兴达
     * @创建时间:2018年9月14日09:14:06
     * @param page 当前页数
     * @param limit 每页条数
     * @param companyId 企业id
     * @return Object
     */
    @RequestMapping(value = "getGoodsList",method = RequestMethod.GET)
    @ResponseBody
    public Object getGoodsList(int page, int limit,Integer companyId,String type,String name) {
    	 if (null == companyId) {
             return AppUtil.returnMapJson("0", "查询失败，请传递企业id", null);
         } 
         try {
             List<Map<String, Object>> goodList = nonConformityStockService.getGoodsList(page, limit, companyId,type,name);
             return AppUtil.returnListJson("1", "查询成功!", goodList);
         } catch (NumberFormatException e) {
             return AppUtil.returnMapJson("0", "查询失败!"+e.getMessage(), null);
         }
    }
}
